package Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者:hfj
 * 功能:144.二叉树的前序遍历
 * 日期: 2025/10/27 10:46
 */
public class PreorderTraversal {

    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();

        PreOrder(root,list);
        return list;
    }

    public void PreOrder(TreeNode root, List<Integer> list) {
        if (root != null){
            list.add(root.val);
            PreOrder(root.left,list);
            PreOrder(root.right,list);
        }
    }

}
